package com.gaotai.wangfei.exam.filter.interceptor;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.gaotai.wangfei.exam.filter.config.IBasicInterceptor;
import com.gaotai.wangfei.exam.filter.config.InterceptorChain;

/**
 * 
 * <p>
 * Description: [关键字拦截]
 * </p>
 * 
 * @author <a href="mailto: wangfei@gaotai.cn">王飞</a>
 * @version $Revision$
 */
public class ForbiddenInterceptor implements IBasicInterceptor
{

	@Override
	public void destroy()
	{
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, InterceptorChain chain) throws IOException,
		ServletException
	{
		System.out.println("start--Forbidden--");
		HttpServletRequest httpReq = (HttpServletRequest) request;
		Enumeration<String> attributeNames = request.getAttributeNames();
		while (attributeNames.hasMoreElements())
		{
			String attributeName = (String) attributeNames.nextElement();
			Object attributeValue = request.getAttribute(attributeName);
			if("香港".equals(attributeValue))
			{
				httpReq.setAttribute(attributeName, "中国香港 【ForbiddenInterceptor已为您自动将‘"+attributeValue+"’划归为‘中国香港’】");
			}
		}
		chain.doFilter(httpReq, response, chain);
		System.out.println("end--Forbidden--");
	}

	@Override
	public void init(String filterConfig) throws ServletException
	{
		// TODO Auto-generated method stub
	}

}
